package com.example.sonny.dutest;

import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.cengalabs.flatui.FlatUI;
import com.example.sonny.Constraint;
import com.example.sonny.bean.BookItem;
import com.example.sonny.dutest.interfaces.BaseActivityI;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.nostra13.universalimageloader.core.ImageLoader;

import org.apache.http.Header;
import org.json.JSONObject;

public class BookDetailActivity extends BaseActivity implements BaseActivityI {

    private TextView tv_name;
    private TextView tv_intro;
    private ImageView iv_book;

    private String book_id;
    private String name;
    private String intro;
    private String action;
    private BookItem book;
    private  String imageUrl;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle extras = getIntent().getExtras();

        book = (BookItem)extras.getSerializable("book");

        intro = book.getIntro();
        name = book.getName();
        imageUrl = book.getImgUrl();
        setContentView(R.layout.activity_book_detail);
        preInit();
        initView();
        initData();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_book_detail, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        if(id == android.R.id.home) {
            // app icon in action bar clicked; goto parent activity.
            this.finish();
            return true;
        }

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void preInit() {

        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);
        actionBar.setBackgroundDrawable(FlatUI.getActionBarDrawable(this, FlatUI.GRASS, false));
    }

    @Override
    public void initView() {
        tv_name = (TextView)findViewById(R.id.name_tv_detail);
        tv_intro = (TextView)findViewById(R.id.intro_tv_detail);
        iv_book = (ImageView)findViewById(R.id.book_image_detail);
    }

    @Override
    public void initData() {
        tv_name.setText(name);
        tv_intro.setText(intro);
        ImageLoader imageLoader = ImageLoader.getInstance();
        imageLoader.displayImage(imageUrl, iv_book);
    }



    @Override
    public void initListener() {

    }

    @Override
    public void onClick(View v) {

    }


}
